// 定义整个模板内函数运行前先执行的函数
// 动态生成目录
function createNavigate(role) {

    // 角色需要本地读取
    sessionStorage.getItem('pname')


    //后期需要按照角色进行显示对应栏目，待定
    // 管理员审核: 超级管理员，屠宰市场管理员，食品监督管理员,屠宰主管
    // 定于常量，便于后期修改
    const ADMIN = '超级管理员'
    const SLAUGHTERSTALLSADMIN = '市场管理员' //管理档口
    const TOSTALLSADMIN = '食品监督管理员'
    const SLAUGHTERADMIN = '屠宰主管' //管理各个市场
    const  MACHINREPAIRE = '脚标机维修人员'
    // role = ''
    let adminContent = ''
    let adminHtml = ''

    if (role == ADMIN) {
        adminContent = `<li><a href="SlaughterHouseStallsAdmin.html">屠宰档口审核</a></li>
        <li><a href="ToStallsAdmin.html">去向档口审核</a></li>
        <li><a href="SlaughterHouseAdmin.html">屠宰市场审核</a></li>`
    } else {
        let adminUrl = role == SLAUGHTERSTALLSADMIN ? 'SlaughterHouseStallsAdmin' : role == TOSTALLSADMIN ? 'ToStallsAdmin' : role == SLAUGHTERADMIN ? 'SlaughterHouseAdmin' : ''
        let adminName = role == SLAUGHTERSTALLSADMIN ? '屠宰档口审核' : role == TOSTALLSADMIN ? '去向档口审核' : role == SLAUGHTERADMIN ? '屠宰市场审核' : ''
        adminContent = `<li><a href="${adminUrl}.html">${adminName}</a></li>`
    }
    adminHtml = `
    <li>
        <a href="javascript: void(0);"><i class="fa fa-user"></i> <span>管理员审核</span> 
        <span class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            ${adminContent}
        </ul>
    </li>`
    // 普通用户
    if (role == '') adminHtml = ''



    let SlaughterHouseStallsHtml = `
    <li>
        <a href="index.html">
            <i class="fi-air-play"></i>
            <!--<span class="badge badge-danger badge-pill float-right">7</span> -->
            <span> 主页 | 控制台 </span>
        </a>
    </li>
    <!-- 地图 -->
    <li>
        <a href="BigData.html"><i class="fi-location-2"></i> <span> 大数据展示 </span></a>
    </li>
    <!--贴码管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-qrcode"></i> <span> 贴标信息管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="LabelingRecordList.html">贴标信息管理</a></li>
            
            <li><a href="BarcodeMachineSearchList.html">贴标历史查询</a></li>
        </ul>
    </li>
    <!-- 基础数据管理 -->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wpforms"></i> <span> 基础数据管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SlaughterHouseList.html">屠宰市场管理</a></li>
        </ul>
    </li>
    ${adminHtml}
    `
    let ToStallsHtml = `
    <li>
        <a href="index.html">
            <i class="fi-air-play"></i>
            <!--<span class="badge badge-danger badge-pill float-right">7</span> -->
            <span> 主页 | 控制台 </span>
        </a>
    </li>
    <!-- 地图 -->
    <li>
        <a href="BigData.html"><i class="fi-location-2"></i> <span> 大数据展示 </span></a>
    </li>
    <!--脚标机监控-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-desktop"></i> <span> 脚标机监控 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineStatusList.html">脚标机监控</a></li>
            <li><a href="BarcodeMachineAlertList.html">报警信息记录</a></li>
        </ul>
    </li>
    <!--贴码管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-qrcode"></i> <span> 贴标信息管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="LabelingRecordList.html">贴标信息管理</a></li>
            
            <li><a href="BarcodeMachineSearchList.html">贴标历史查询</a></li>
        </ul>
    </li>
    <!-- 基础数据管理 -->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wpforms"></i> <span> 基础数据管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SlaughterHouseList.html">屠宰市场管理</a></li>
            <li><a href="ToMarketList.html">去向市场管理</a></li>
            <li><a href="StallsList.html">屠宰档口管理</a></li>
            <li><a href="AllBarcodeMachineList.html">脚标机管理</a></li>
            <li><a href="BarcodeMachineList.html">脚标机关联信息管理</a></li>
            <li><a href="PoultryCategoryList.html">禽类信息管理</a></li>
        </ul>
    </li>
    <!--条形码发放回收记录-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-barcode"></i> <span> 条形码发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeGrantList.html">条形码发放记录管理</a></li>
            <li><a href="BarcodeRecoveryList.html">条形码回收记录管理</a></li>
        </ul>
    </li>
    ${adminHtml}
    <!--用户管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-user"></i> <span> 用户管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SysUserList.html">用户信息管理</a></li>
            <li><a href="SysUserRoleList.html">用户角色管理</a></li>
        </ul>
    </li>
    `
    let SlaughterHouseHtml = `
    <li>
        <a href="index.html">
            <i class="fi-air-play"></i>
            <!--<span class="badge badge-danger badge-pill float-right">7</span> -->
            <span> 主页 | 控制台 </span>
        </a>
    </li>
    <!-- 地图 -->
    <li>
        <a href="BigData.html"><i class="fi-location-2"></i> <span> 大数据展示 </span></a>
    </li>
    <!--脚标机监控-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-desktop"></i> <span> 脚标机监控 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineStatusList.html">脚标机监控</a></li>
            
            <li><a href="BarcodeMachineAlertList.html">报警信息记录</a></li>
        </ul>
    </li>
    <!--贴码管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-qrcode"></i> <span> 贴标信息管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="LabelingRecordList.html">贴标信息管理</a></li>
            
            <li><a href="BarcodeMachineSearchList.html">贴标历史查询</a></li>
        </ul>
    </li>
    <!-- 基础数据管理 -->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wpforms"></i> <span> 基础数据管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SlaughterHouseList.html">屠宰市场管理</a></li>
            <li><a href="ToMarketList.html">去向市场管理</a></li>
            <li><a href="StallsList.html">屠宰档口管理</a></li>
            <li><a href="AllBarcodeMachineList.html">脚标机管理</a></li>
            <li><a href="BarcodeMachineList.html">脚标机关联信息管理</a></li>
            <li><a href="PoultryCategoryList.html">禽类信息管理</a></li>
            <li><a href="PoultryParentList.html">父级类别管理</a></li>
        </ul>
    </li>
    <!--条形码发放回收记录-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-barcode"></i> <span> 条形码发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeGrantList.html">条形码发放记录管理</a></li>
            <li><a href="BarcodeRecoveryList.html">条形码回收记录管理</a></li>
        </ul>
    </li>
    ${adminHtml}
    <!--用户管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-user"></i> <span> 用户管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SysUserList.html">用户信息管理</a></li>
            <li><a href="SysUserRoleList.html">用户角色管理</a></li>
        </ul>
    </li>
    `
    let MachineRequireHtml = `
    <!--脚标机监控-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-desktop"></i> <span> 脚标机监控 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineStatusList.html">脚标机监控</a></li>  
            <li><a href="BarcodeMachineAlertList.html">报警信息记录</a></li>
        </ul>
    </li>
    <!--脚标机发放回收-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-print"></i> <span> 脚标机发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineGrantList.html">脚标机发放管理</a></li>
            <li><a href="BarcodeMachineRecoveryList.html">脚标机回收管理</a></li>
        </ul>
    </li>
    <!--脚标机报废记录-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wrench"></i> <span> 脚标机报废维修管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineRepairList.html">脚标机报修记录管理</a></li>
            <li><a href="BarcodeMachineScrapList.html">脚标机报废记录管理</a></li>
        </ul>
    </li>
    `



    // 整个模板
    let allHtml = `
    <li>
        <a href="index.html">
            <i class="fi-air-play"></i>
            <!--<span class="badge badge-danger badge-pill float-right">7</span> -->
            <span> 主页 | 控制台 </span>
        </a>
    </li>
    <!-- 地图 -->
    <li>
        <a href="BigData.html"><i class="fi-location-2"></i> <span> 大数据展示 </span></a>
    </li>
    <!--脚标机监控-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-desktop"></i> <span> 脚标机监控 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineStatusList.html">脚标机监控</a></li>
            
            <li><a href="BarcodeMachineAlertList.html">报警信息记录</a></li>
        </ul>
    </li>
    <!--贴码管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-qrcode"></i> <span> 贴标信息管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="LabelingRecordList.html">贴标信息管理</a></li>
            
            <li><a href="BarcodeMachineSearchList.html">贴标历史查询</a></li>
        </ul>
    </li>
    <!-- 基础数据管理 -->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wpforms"></i> <span> 基础数据管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SlaughterHouseList.html">屠宰市场管理</a></li>
            <li><a href="ToMarketList.html">去向市场管理</a></li>
            <li><a href="StallsList.html">屠宰档口管理</a></li>
            <li><a href="AllBarcodeMachineList.html">脚标机管理</a></li>
            <li><a href="BarcodeMachineList.html">脚标机关联信息管理</a></li>
            <li><a href="IdCardList.html">ID卡数据管理</a></li>
            <li><a href="PoultryCategoryList.html">禽类信息管理</a></li>
            <li><a href="PoultryParentList.html">父级类别管理</a></li>
        </ul>
    </li>
    <!--条形码发放回收记录-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-barcode"></i> <span> 条形码发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeGrantList.html">条形码发放记录管理</a></li>
            <li><a href="BarcodeRecoveryList.html">条形码回收记录管理</a></li>
        </ul>
    </li>
    <!--脚标机发放回收-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-print"></i> <span> 脚标机发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineGrantList.html">脚标机发放管理</a></li>
            <li><a href="BarcodeMachineRecoveryList.html">脚标机回收管理</a></li>
        </ul>
    </li>
    <!--脚标机报废记录-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-wrench"></i> <span> 脚标机报废维修管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="BarcodeMachineRepairList.html">脚标机报修记录管理</a></li>
            <li><a href="BarcodeMachineScrapList.html">脚标机报废记录管理</a></li>
        </ul>
    </li>
    <!--ID卡发放管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-id-card"></i> <span> ID卡发放回收管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="IdCardGrantList.html">ID卡发放记录管理</a></li>
            <li><a href="IdCardRecoveryList.html">ID卡回收记录管理</a></li>
        </ul>
    </li>
    ${adminHtml}
    <!--用户管理-->
    <li>
        <a href="javascript: void(0);"><i class="fa fa-user"></i> <span> 用户管理 </span> <span
                class="menu-arrow"></span></a>
        <ul class="nav-second-level" aria-expanded="false">
            <li><a href="SysUserList.html">用户信息管理</a></li>
            <li><a href="SysUserRoleList.html">用户角色管理</a></li>
        </ul>
    </li>
    <!--角色管理-->
    <li>
        <a href="SysRoleMenuList.html"><i class="fa fa-users"></i> <span> 角色权限管理 </span> </a>
    </li>
    <!--日志管理-->
    <li>
        <a href="LogRecordList.html"><i class="fa fa-qrcode"></i> <span>日志信息管理 </span></a>
    </li>
    `
    console.log(role)
    let str = ''
    if (role == ADMIN) {
        str = allHtml
    }else{
        str = role == SLAUGHTERSTALLSADMIN ? SlaughterHouseStallsHtml : role == TOSTALLSADMIN ? ToStallsHtml : role == SLAUGHTERADMIN ? SlaughterHouseHtml : MachineRequireHtml

    }
    $('#side-menu').html(str)

}





function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
}

function setCookie(name, value, time) {
    var strsec = getsec(time);
    var exp = new Date();
    exp.setTime(exp.getTime() + strsec * 1);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//发送权限请求
function getRole() {
    var url = window.location.pathname; //获取url
    url = decodeURI(url.split("/")[1]);
    var username = getCookie("loginUsername")
    $.ajax({
        type: "GET",
        url: URL + 'checkOprate?url=/' + url + '&username=' + username,
        data: {},
        async: false,
        dataType: "json",
        success: function (data) {
            data = data.object
            if (data === null) {
                $('.fa-plus').parent().hide()
                $('.fa-th-list').parent().hide()
                $('.fa-edit').parent().hide()
                $('.fa-trash').parent().hide()
            }
            if ($.inArray("t1", data) === -1) {
                $('.fa-plus').parent().hide()
            }
            if ($.inArray("t2", data) === -1) {
                $('.fa-trash').parent().hide()
            }
            if ($.inArray("t3", data) === -1) {
                $('.fa-edit').parent().hide()
            }
            if ($.inArray("t4", data) === -1) {
                $('.fa-th-list').parent().hide()
            }
            return data.object

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {}
    });
}